# -*-coding:utf-8-*-

from tests.apis.http import *
from tests.apis.base import BaseAPI


class Transfers(BaseAPI):
    def __init__(self, *args, **kwargs):
        super(Transfers, self).__init__(*args, **kwargs)

    def create_transfer(self, *args, **kwargs):
        response = http_post('platform/api/transfers', kwargs, self.query)
        return self.assert_response_success_data(response, **kwargs)

    def delete_transfer(self, *args, **kwargs):
        transfer_id = kwargs['transfer_id']
        response = http_delete('platform/api/transfers/%s' % transfer_id, query=self.query)
        return self.assert_response_success_data(response)

    # def update_transfer(self, *args, **kwargs):
    #     transfer_id = kwargs.pop('transfer_id')
    #     response = http_put('platform/api/transfers/%s' % transfer_id, kwargs, query=self.query)
    #     return self.assert_response_success_data(response)

    def update_transfer_status(self, *args, **kwargs):
        transfer_id = kwargs.pop('transfer_id')
        response = http_put('platform/api/transfers/%s/status' % transfer_id, kwargs, query=self.query)
        return self.assert_response_success_data(response)

    def get_transfer(self, *args, **kwargs):
        transfer_id = kwargs.pop('transfer_id')
        response = http_get('platform/api/transfers/%s' % transfer_id, query=self.query)
        return self.assert_response_success_data(response)

    def get_transfer_statistics(self, *args, **kwargs):
        response = http_get('platform/api/transfers/statistics', query=self.query)
        return self.assert_response_success_data(response)

    def get_transfer_list(self, *args, **kwargs):
        return self._get_transfer_list(**kwargs)

    def get_transfer_count(self, *args, **kwargs):
        return self._get_transfer_list(get_count=True, **kwargs)

    def _get_transfer_list(self, get_count=False, **kwargs):
        query = self.query_from_kwargs(**kwargs)
        url = 'platform/api/transfers'
        if get_count:
            url += '/count'
        response = http_get(url, query)
        return self.assert_response_success_data(response)

